//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package b;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Aservlet extends HttpServlet {
    public static test getzhmm = new test();
    private String message;

    public Aservlet() {
    }

    public void init() throws ServletException {
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<h1>小贩砸牛逼~~~</h1>");
    }

    public static boolean isContainChinese(String str) {
        Pattern p = Pattern.compile("[一-龥]");
        Matcher m = p.matcher(str);
        return m.find();
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=GBK");
        PrintWriter out = response.getWriter();
        response.setContentType("text/html");
        String account = request.getParameter("Account");
        account = new String(account.getBytes("ISO-8859-1"), "gbk");
        if (isContainChinese(account)) {
            out.print("<script>alert('账号不能是中文~'); window.location='index.jsp' </script>");
        } else {
            System.out.println(account + "111");
            String password = request.getParameter("Password");
            String bl = request.getParameter("bl");
            if (bl.equals("S")) {
                try {
                    request.getRequestDispatcher("/WEB-INF/jsp/signup.jsp").forward(request, response);
                } catch (Exception var10) {
                    out.print("<script>alert('Sorry,something is wrong.'); window.location='index.jsp' </script>");
                }
            } else {
                String name;
                if (bl.equals("L")) {
                    name = getzhmm.isLogin(account, password);
                    if (!name.equals("")) {
                        try {
                            request.setAttribute("Name", name);
                            System.out.println(name);
                            request.getRequestDispatcher("/WEB-INF/jsp/welcome.jsp").forward(request, response);
                        } catch (Exception var9) {
                            out.print("<script>alert('Sorry,something is wrong.'); window.location='index.jsp' </script>");
                        }
                    } else {
                        out.print("<script>alert('Sorry,your account or password is wrong.'); window.location='index.jsp' </script>");
                    }
                } else if (bl.equals("Ss")) {
                    name = request.getParameter("Name");
                    name = new String(name.getBytes("ISO-8859-1"), "gbk");
                    System.out.print(name + "222");
                    String tc = getzhmm.signup(account, password, name);
                    out.print("<script>alert('" + tc + "'); window.location='index.jsp' </script>");
                }
            }

        }
    }
}
